package com.pig4cloud.pig.admin.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.admin.api.entity.BsAircorpManageEntity;
import com.pig4cloud.pig.admin.service.BsAircorpManageService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.common.security.annotation.Inner;
import org.springframework.security.access.prepost.PreAuthorize;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 航空公司管理
 *
 * @author pig
 * @date 2025-04-03 17:45:40
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/bsAircorpManage" )
@Tag(description = "bsAircorpManage" , name = "航空公司管理管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class BsAircorpManageController {

    private final BsAircorpManageService bsAircorpManageService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param bsAircorpManage 航空公司管理
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
	@Inner(value = false)
    public R getBsAircorpManagePage(@ParameterObject Page page, @ParameterObject BsAircorpManageEntity bsAircorpManage) {
        LambdaQueryWrapper<BsAircorpManageEntity> wrapper = Wrappers.lambdaQuery();
        return R.ok(bsAircorpManageService.page(page, wrapper));
    }

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param bsAircorpManage 航空公司管理
	 * @return
	 */
	@Operation(summary = "分页查询" , description = "分页查询" )
	@GetMapping("/list" )
	@Inner(value = false)
	public R list(@ParameterObject BsAircorpManageEntity bsAircorpManage) {
		LambdaQueryWrapper<BsAircorpManageEntity> wrapper = Wrappers.lambdaQuery();
		return R.ok(bsAircorpManageService.list( wrapper));
	}

    /**
     * 通过id查询航空公司管理
     * @param aircorpId id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{aircorpId}" )
	@Inner(value = false)
    public R getById(@PathVariable("aircorpId" ) Long aircorpId) {
        return R.ok(bsAircorpManageService.getById(aircorpId));
    }

    /**
     * 新增航空公司管理
     * @param bsAircorpManage 航空公司管理
     * @return R
     */
    @Operation(summary = "新增航空公司管理" , description = "新增航空公司管理" )
    @SysLog("新增航空公司管理" )
    @PostMapping
	@Inner(value = false)
    public R save(@RequestBody BsAircorpManageEntity bsAircorpManage) {
        return R.ok(bsAircorpManageService.saveAir(bsAircorpManage));
    }

    /**
     * 修改航空公司管理
     * @param bsAircorpManage 航空公司管理
     * @return R
     */
    @Operation(summary = "修改航空公司管理" , description = "修改航空公司管理" )
    @SysLog("修改航空公司管理" )
    @PutMapping
	@Inner(value = false)
    public R updateById(@RequestBody BsAircorpManageEntity bsAircorpManage) {
        return R.ok(bsAircorpManageService.updateById(bsAircorpManage));
    }

    /**
     * 通过id删除航空公司管理
     * @param ids aircorpId列表
     * @return R
     */
    @Operation(summary = "通过id删除航空公司管理" , description = "通过id删除航空公司管理" )
    @SysLog("通过id删除航空公司管理" )
    @DeleteMapping
	@Inner(value = false)
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(bsAircorpManageService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param bsAircorpManage 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
	@Inner(value = false)
    public List<BsAircorpManageEntity> export(BsAircorpManageEntity bsAircorpManage,Long[] ids) {
        return bsAircorpManageService.list(Wrappers.lambdaQuery(bsAircorpManage).in(ArrayUtil.isNotEmpty(ids), BsAircorpManageEntity::getAircorpId, ids));
    }

	/**
	 * 初始化航管
	 * @param bsAircorpManage
	 * @return
	 */
	@PostMapping("/initAir")
	@Inner(value = false)
	public R initBalace(BsAircorpManageEntity bsAircorpManage) {
		return R.ok();
	}
}